package civicinity.ist.psu.edu.rssfeed;

import java.util.ArrayList;

import civicinity.ist.psu.edu.R;
import civicinity.ist.psu.edu.R.id;
import civicinity.ist.psu.edu.R.layout;
import civicinity.ist.psu.edu.adapter.CivicinityRSSInfoAdapter;
import civicinity.ist.psu.edu.adapter.CivicinityShareListViewAdapter;
import civicinity.ist.psu.edu.constants.Constants;
import civicinity.ist.psu.edu.databases.CivicinityDatabase;
import civicinity.ist.psu.edu.share.ShareItem;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class CivicinityFeedLists extends Activity implements OnItemClickListener{

	private ArrayList<RSSDBItem> mArr = null;
	private CivicinityDatabase mDB;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.rss_feed_lists);
	    
        // connect to the DB helper
        mDB = new CivicinityDatabase(this);
	    
	    mArr = mDB.getFeeds();
	    
	    setListView();
	    // TODO Auto-generated method stub
	}
	
	private void setListView() {
		
		// set the RSS items
		ListView vList = (ListView) findViewById(R.id.itemlist);
		CivicinityRSSInfoAdapter adapter = new CivicinityRSSInfoAdapter(this, R.layout.share_item, mArr);
		vList.setAdapter(adapter);
		vList.setOnItemClickListener(this);
		vList.setSelection(0);
		
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
		// TODO Auto-generated method stub
	}
	
	/**
	 * Menu option(non-Javadoc)
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 */
	public boolean onCreateOptionsMenu(Menu menu){
		super.onCreateOptionsMenu(menu);
		
		menu.add(0, 1, 0, getString(R.string.menu_manage_feed)).setIcon(android.R.drawable.ic_menu_manage);
		//menu.add(0, 2, 0, getString(R.string.menu_info_rss)).setIcon(android.R.drawable.ic_menu_info_details);
			
		return true;
	}
	
	/**
	 * Menu option selection handling(non-Javadoc)
	 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
	 */
	public boolean onOptionsItemSelected(MenuItem item){

		switch(item.getItemId()){
			case 1:
				Toast.makeText(CivicinityFeedLists.this, "Coming soon...", Toast.LENGTH_SHORT).show();
				return true;
			//case 2:
			//	Toast.makeText(CivicinityFeedLists.this, "Coming soon...", Toast.LENGTH_SHORT).show();
			//	return true;
			}
			
		return false;
	}

}
